<!--
 * @Descripttion:
 * @Author: Silence
 * @Date: 2023-08-13 09:09:26
 * @LastEditors: Silence
 * @LastEditTime: 2023-08-16 08:45:29
-->
<template>
  <div class="dialog_com">

    <el-dialog
      title="新增区域"
      :visible="centerDialogVisible"
      :before-close="handleClose"
      width="45%"
    >
      <el-form ref="ruleForm" :rules="rules" :model="ruleForm" label-width="100px" class="dialog_ruleForm">
        <el-form-item label="点位名称" prop="name" style="font-size:13px">
          <el-input v-model="ruleForm.name" maxlength="15" show-word-limit />
        </el-form-item>
        <el-form-item label="所在区域" prop="regionId">
          <el-select v-model="ruleForm.regionId" placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="item in optionsRegion"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="所属商圈" prop="businessId">
          <el-select v-model="ruleForm.businessId" placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="归属合作商" prop="ownerName">
          <el-select v-model="ruleForm.ownerName" placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="item in optionsPartner"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址" prop="addr">
          <el-cascader
            v-model="city"
            :options="cityOptions"
            placeholder="请选择"
            style="width: 100%;"
            @change="changeProvince"
          />
        </el-form-item>
        <el-form-item prop="address">
          <el-input v-model="address" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleClose">取消</el-button>
          <el-button @click="submitForm()">确定</el-button>
        </el-form-item>
      </el-form>
    <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span> -->
    </el-dialog>
  </div>
</template>
<script>
import cityOptions from '@/components/address/city_data2017_element'
import { getBusinessTypeListApi, getRegionListApi, getPartnerListApi } from '@/api/area'
export default {
  name: '',
  props: {
    centerDialogVisible: {
      type: Boolean,
      default: false
    },
    ruleForm: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      pages: {
        pageIndex: 1,
        pageSize: 1000
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      },
      cityOptions: cityOptions,
      options: [],
      optionsRegion: [],
      optionsPartner: [],
      city: [],
      address: ''
    }
  },
  computed: {
  },
  watch: {
    address(newVal) {
      console.log(newVal)
      this.ruleForm.addr = this.city[0] + this.city[1] + (this.city[2] || '') + newVal
    }
  },
  created() {
    this.getBusinessTypeList()
    this.getRegionList()
    this.getPartnerList()
  },
  methods: {
    // 获取商圈类型
    async getBusinessTypeList() {
      const res = await getBusinessTypeListApi()
      console.log(res)
      this.options = res.data
    },
    submitForm() {
      this.$emit('submitForm')
    },
    resetForm() {
      // this.$options.ruleForm()
    },
    changeProvince(e) {
      console.log(e)
    },
    // 关闭表单
    handleClose() {
      this.$emit('clearData')
      this.city = []
      this.address = ''
    },
    // 获取区域列表
    async getRegionList() {
      const res = await getRegionListApi(this.pages)
      console.log(res, 111)
      this.optionsRegion = res.data.currentPageRecords
    },
    // 获取所属商圈列表
    async getPartnerList() {
      const res = await getPartnerListApi(this.pages)
      console.log(res, 222)
      this.optionsPartner = res.data.currentPageRecords
    }
  }
}
</script>
<style lang='scss'>
.dialog_com{
  .el-dialog {
    border-radius: 12px;
    padding-right: 40px;
  }
}
</style>
